package com.snake.vargoappstore.result;

import com.snake.mylibrary.loader.DynamicResult;
import com.snake.mylibrary.net.HttpStatus;
import com.snake.vargoappstore.db.AppInfo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


public class ClassFragmentResult extends DynamicResult{
    private AppInfo[] mAppInfos ;
    public ClassFragmentResult(JSONObject jo, HttpStatus err) {
        super(jo, err);
    }

    @Override
    public boolean isDataValid() {
        return true;
    }

    @Override
    protected void parserOriginalData(JSONObject obj) {
        try {
            JSONArray array = obj.getJSONArray("data");
            mAppInfos = new AppInfo[array.length()];
            for(int i = 0; i<array.length(); i++){
                JSONObject o = (JSONObject) array.get(i);
                String subId = o.optString("subId","");
                String name = o.optString("name","");
                String iconUrl = o.optString("icon","");
                long size = o.optLong("size",0);
                AppInfo appInfo = new AppInfo(subId, iconUrl, name, size);
                mAppInfos[i] = appInfo;
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public AppInfo[] getAppInfos() {
        return mAppInfos;
    }
}
